package org.example.yygh.hosp.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.example.common.result.Result;
import org.example.yygh.hosp.service.HospitalSetService;
import org.example.yygh.model.hosp.HospitalSet;
import org.example.yygh.vo.hosp.HospitalSetQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "医院设置管理")
@RestController
@RequestMapping("/admin/hosp/hospitalSet")
public class HospitalSetController {
    @Autowired
    private HospitalSetService hospitalSetService;

    @ApiOperation(value = "获取所有医院设置信息")
    @GetMapping("findAll")
    public Result<?> findAllHospitalSet() {
        return Result.ok(hospitalSetService.list());
    }

    @ApiOperation(value = "逻辑删除医院设置信息")
    @DeleteMapping("{id}")
    public boolean removeHospSet(@PathVariable Long id) {
        return hospitalSetService.removeById(id);
    }

    @GetMapping("findPageHospSet/{current}/{limit}")
    public Result findPageHospSet(
            @PathVariable long current,
            @PathVariable long limit,
            HospitalSetQueryVo hospitalSetQueryVo){//创建page对象，传递当前页，每页记录数

        Page<HospitalSet> page = new Page<>(current,limit);
        QueryWrapper<HospitalSet> wrapper = new QueryWrapper<>();

        String hosname = hospitalSetQueryVo.getHosname();//医院名称
        String hoscode = hospitalSetQueryVo.getHoscode();//医院编号

        wrapper.like("hosname",hospitalSetQueryVo.getHosname());
        wrapper.eq("hoscode",hospitalSetQueryVo. getHoscode());

        if (!StringUtils.isEmpty(hosname)) {
            wrapper.like("hosname", hospitalSetQueryVo.getHosname());
        }

        if (!StringUtils.isEmpty(hoscode)) {
            wrapper.like("hoscode", hospitalSetQueryVo.getHoscode());
        }

//调用方法实现分页查询
        Page<HospitalSet> pageHospitalSet = hospitalSetService.page(page, wrapper);
        return Result.ok(pageHospitalSet);
    }
}
